home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / hash.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-25  |  3.3 KB  |  100 lines

  1. /* This file is part of XEmacs.
  2.  
  3. XEmacs is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the
  5. Free Software Foundation; either version 2, or (at your option) any
  6. later version.
  7.  
  8. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11. for more details.
  12.  
  13. You should have received a copy of the GNU General Public License
  14. along with XEmacs; see the file COPYING.  If not, write to the Free
  15. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  16.  
  17. /* Synched up with: Not in FSF. */
  18.  
  19. #ifndef _HASH_H_
  20. #define _HASH_H_
  21.  
  22. typedef struct
  23. {
  24.   CONST void *key;
  25.   void         *contents;
  26. } hentry;
  27.  
  28. struct _C_hashtable
  29. {
  30.   hentry    *harray;
  31.   long        zero_set;
  32.   void        *zero_entry;
  33.   unsigned int    size;        /* size of the hasharray */
  34.   unsigned int    fullness;    /* number of entries in the hashtable */
  35.   unsigned long (*hash_function) (CONST void *);
  36.   int        (*test_function) (CONST void *, CONST void *);
  37. #ifdef emacs
  38.   Lisp_Object elisp_table;
  39. #endif
  40. };
  41.  
  42. typedef struct _C_hashtable *c_hashtable;
  43.  
  44. /* size is the number of initial entries. The hashtable will be grown
  45.    automatically if the number of entries approaches the size */
  46. extern c_hashtable make_hashtable (unsigned int size);
  47.  
  48. extern c_hashtable make_general_hashtable 
  49.   (unsigned int hsize, unsigned long (*hash_function) (CONST void *),
  50.    int (*test_function)(CONST void *, CONST void *));
  51.  
  52. extern c_hashtable make_strings_hashtable (unsigned int hsize);
  53.  
  54. /* clears the hash table. A freshly created hashtable is already cleared up */
  55. extern void clrhash (c_hashtable hash);
  56.  
  57. /* frees the table and substructures */
  58. extern void free_hashtable (c_hashtable hash);
  59.  
  60. /* returns a hentry whose key is 0 if the entry does not exist in hashtable */
  61. extern CONST void* gethash (CONST void* key, c_hashtable hash, 
  62.                             CONST void** ret_value);
  63.  
  64. /* key should be different from 0 */
  65. extern void puthash (CONST void* key, void* contents, c_hashtable hash);
  66.  
  67. /* delete the entry which key is key */
  68. extern void remhash (CONST void* key, c_hashtable hash);
  69.  
  70. typedef void (*maphash_function) (CONST void* key, void* contents, 
  71.                                   void* arg);
  72.  
  73. typedef int (*remhash_predicate) (CONST void* key, CONST void* contents,
  74.                                   void* arg);
  75.  
  76. typedef void (*generic_hashtable_op) (c_hashtable table, 
  77.                                       void *arg1, void *arg2, void *arg3);
  78.  
  79. /* calls mf with the following arguments:  key, contents, arg; for every 
  80.    entry in the hashtable */
  81. extern void maphash (maphash_function fn, c_hashtable hash, void* arg);
  82.  
  83. /* delete objects from the table which satisfy the predicate */
  84. extern void 
  85. map_remhash (remhash_predicate predicate, c_hashtable hash, void *arg);
  86.  
  87. /* copies all the entries of src into dest -- dest is modified as needed
  88.    so it is as big as src. */ 
  89. extern void copy_hash (c_hashtable dest, c_hashtable src);
  90.  
  91. /* makes sure that hashtable can hold at least needed_size entries */
  92. void
  93. expand_hashtable (c_hashtable hash, unsigned int needed_size);
  94.  
  95. #ifdef emacs    /* for elhash.c */
  96. extern unsigned int compute_harray_size (unsigned int);
  97. #endif
  98.  
  99. #endif /* _HASH_H_ */
  100.